:SHOW_KEYBOARD
{
    ShowKeyboard(PointerOfaSpaceToWrite, MaxChars)
    Use with opcode 0AB1
    
    Example: 0AB1: call_scm_func @SHOW_KEYBOARD 2 pointer 0@ max_chars 7
    
    Return: 
        True = Player write anything, otherwise false
        False = Player doesn't write anything
        
    -- www.link2012world.blogspot.com -- 
}


wait 0
8@ = 0 // Number of Chars
0AA5: call 0x588BE0 num_params 4 pop 4 0 1 0 "-"
0A8C: write_memory 0x969110 size 1 value 0 virtual_protect 0
0A8C: write_memory 0@ size 4 value 0 virtual_protect 0

:KEYBOARD__WHILE
while 8AB0: not key_pressed 0xD
    wait 0
    0A8D: 6@ = read_memory 0x969110 size 1 virtual_protect 0

    if 6@ <> 0
    then
        if 002D: 8@ >= 1@
        then
            :KEYBOARD__0
            0A8C: write_memory 0x969110 size 1 value 0 virtual_protect 0
            continue
        end
        if and
        6@ < 65
        6@ > 90
        then
            if and
            6@ >= 48
            6@ <= 57
            jf @KEYBOARD__0
        end
        if 8AB0:   not key_pressed 0x10 
        then
            if 6@ > 57
            then
                6@ += 32
            end
        end
        gosub @KEYBOARD__SUB
        jump @KEYBOARD__0
    end

    if 802D: not 8@ >= 1@
    then
        for 6@ = 0x60 to 0x69 
            0AB0:   key_pressed 6@
            jf continue
            6@ -= 0x30
            gosub @KEYBOARD__SUB
            wait 100
            jump @KEYBOARD__WHILE
        end
    end

    if 0AB0:   key_pressed 0x8 //Backspace
    then
        8@ > 0
        jf continue
        0085: 7@ = 0@
        005A: 7@ += 8@
        7@ -= 1
        03E6: remove_text_box
        0A8C: write_memory 7@ size 1 value 0 virtual_protect 0
        8@ -= 1
        0AA5: call 0x588BE0 num_params 4 pop 4 0 1 0 0@
        wait 50   
    end
    
    
    8AB0:   not key_pressed 0xD // Exit
    jf break
end
03E6: remove_text_box
0ACD: show_text_highpriority 0@ time 2000
if 8@ > 0
then
    0485: return_true
else
    059A: return_false
end
0AB2: ret 0

:KEYBOARD__SUB
0085: 10@ = 0@
005A: 10@ += 8@
0A8C: write_memory 10@ size 1 value 6@ virtual_protect 0
10@ += 1
0A8C: write_memory 10@ size 1 value 0 virtual_protect 0
03E6: remove_text_box
8@ += 1    
0A8C: write_memory 0x969110 size 1 value 0 virtual_protect 0
0AA5: call 0x588BE0 num_params 4 pop 4 0 1 0 0@
return

